home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / comm / ca29_3.zip / REMAP.CMD < prev    next >
OS/2 REXX Batch file  |  1992-03-23  |  28KB  |  1,165 lines

  1.    S29 = "INTERNAL"                     ; Set your editor here
  2. ;                    ; .. "INTERNAL" -> Our own editor
  3. ; ----- COM-AND Compile remap table
  4. ;
  5. ;    This script opens a window asking 1) to compile new remap, 2) turn
  6. ;    remapping on, and 3) turn remap off.
  7. ;
  8. ;    The big job, of course, if the compilation of remapping values.
  9. ;    The result of the compilation is saved unconditionally as COM-AND.RMP.
  10. ;
  11. ;    R.McG, commenced 2/89
  12. ;           updated     3/92 (to use internal editor)
  13. ; ----- Usages -----------------
  14. ;    S29 -----> The fully qualified EDITOR program file name
  15. ;    S19 -----> COM-AND.RMP file name to be used
  16. ;    S18 -----> Source file being compiled
  17. ;    N99 -----> The # of errors in compilation
  18. ;    N98 -----> The output file size
  19. ;    N97 -----> # name commands to allow (set in SELECT)
  20. ;    FLAG(9) -> Escape during compile (wait for another ESC)
  21. ;    FLAG(8) -> If true, syntax check only
  22. ; ------------------------------
  23. ;    Initialization
  24. ;
  25. ;* TRACE ON
  26.    ON ESCAPE GOSUB Exit         ; SAVE is performed in Window
  27.    LEGEND " Remap compiler (ver 1.2)"
  28.    SET TTHRU OFF            ; Disallow typeahead
  29.    GOSUB Set_Fname            ; Get current fname
  30.    UPPER S19                ; Make nice for display
  31. ;
  32. ;    Open a window
  33. ;
  34.    GOSUB Window             ; Open main window
  35. ;
  36. ;    Wait for a keystroke
  37. ;
  38. Keyin:
  39.    LOCATE 18,20
  40.    ATSAY  18,20 (default) "   "
  41.    KEYGET S0
  42.    IF NULL S0(1:3)
  43.       ATSAY 18,20 (default) S0
  44.       ENDIF
  45. ;
  46. ;    Interpret the response
  47. ;
  48.    SWITCH S0
  49.       CASE "1"                                  ; Compile
  50.     GOSUB Compile
  51.       ENDCASE
  52.       CASE "2"                                  ; Syntax
  53.     GOSUB Syntax
  54.       ENDCASE
  55.       CASE "3"                                  ; Search for file
  56.     GOSUB Alt_F
  57.       ENDCASE
  58.       CASE "4"                                  ; Edit a file
  59.     GOSUB Edit
  60.       ENDCASE
  61.       CASE "5"                                  ; Remap on
  62.     GOSUB Mapon
  63.       ENDCASE
  64.       CASE "6"                                  ; Remap off
  65.     GOSUB Mapoff
  66.       ENDCASE
  67.       DEFAULT                    ; None of the above
  68.      SOUND 100,100
  69.      GOTO Keyin                ; Try again
  70.       ENDCASE
  71.    ENDSWITCH
  72.    GOTO KEYIN
  73. ;
  74. ; ----- Subroutine Exit - terminate the process
  75. ;
  76. Exit:
  77.     DO                ; CLose any open windows
  78.       WCLOSE
  79.       UNTIL FAILURE
  80.     EXIT
  81. ;
  82. ; ----- Subroutine Mapon - turn on mapping (using current file)
  83. ;
  84. MapOn:
  85.     SET REMAP ON            ; Enable
  86.     RETURN
  87. ;
  88. ; ----- Subroutine MapOff - turn off mapping
  89. ;
  90. MapOff:
  91.     SET REMAP OFF            ; Disable
  92.     RETURN
  93. ;
  94. ; ----- Perform an Alt-F - file search
  95. ;
  96. Alt_F:
  97.     WOPEN 10,1  13,78 (default) ErrEsc
  98.     ATSAY 10,3  (default) " Search for files "
  99.     ATSAY 11,3  (default) "Enter a search template (e.g. 'd:\subd\x*.AR?')."
  100.     ATSAY 12,3  (default) "-> "
  101.     ATSAY 13,30 (default) " Press ESC to cancel "
  102.     ATGET 12,6  (default) 50 S0
  103.     WCLOSE
  104. ;
  105. ;    If not null, perform the request
  106. ;
  107.     IF NOT NULL S0
  108.        DIR S0                ; Make upper case
  109.        ENDIF
  110.     RETURN
  111. ;
  112. ; ----- Invoke an editor to edit a file
  113. ;
  114. Edit:
  115.     IF NOT NULL S29 GOTO Edit100
  116. ;
  117. ;    Open a window and ask for the editor's name
  118. ;
  119.     WOPEN 10,1  13,78 (default) ErrEsc
  120.     ATSAY 10,3  (default) " Edit file "
  121.     ATSAY 11,3  (default) "Enter the editor's name, fully qualified (e.g. C:\PE.EXE)."
  122.     ATSAY 12,3  (default) "-> "
  123.     ATSAY 13,30 (default) " Press ESC to cancel "
  124.     ATGET 12,6  (default) 50 S0        ; ErrEsc clears S0, so we use it
  125.     WCLOSE
  126.  
  127.     IF NULL S0 RETURN            ; Return on empty answer
  128.     S29 = S0                ; Save for next time
  129. ;
  130. ;    Open another window and ask for the file name
  131. ;
  132. Edit100:
  133.     WOPEN 10,1  13,78 (default) ErrEsc
  134.     ATSAY 10,3  (default) " Edit file "
  135.     ATSAY 11,3  (default) "Enter the file name to be edited:"
  136.     ATSAY 12,3  (default) "-> "
  137.     ATSAY 13,30 (default) " Press ESC to cancel "
  138.     ATGET 12,6  (default) 50 S0        ; ErrEsc clears S0, so we use it
  139.     WCLOSE
  140. ;
  141. ;    If not null, perform the request
  142. ;
  143.     IF NOT NULL S0 and (NOT NULL S29 and NOT FIND S29 "INTERNAL")
  144.        RUN S29 * " " *S0                    ; Make upper case
  145.        IF FAILED S29 = "INTERNAL"           ; Clear S29 if failed
  146.        ENDIF
  147.     IF (NULL S29 or FIND S29 "INTERNAL") and NOT NULL S0 EDIT S0
  148.     RETURN
  149. ;
  150. ; ----- Construct the file name we'll use for COM-AND.RMP
  151. ;
  152. Set_Fname:
  153.     S19 = "COM-AND.RMP"     ; Default to current subdir
  154.     IF ISFILE S19        ; Look for file on default subdir
  155.        RETURN        ; Exit here
  156.        ENDIF
  157. ;
  158. ; ----- Construct the file with the COM-AND= pathing (if provided)
  159. ;
  160.     ENVIRON S1 "COM-AND="   ; Look for COM-AND= environment var
  161.     IF FOUND        ; If environment variable found
  162.        LENGTH S1 N0     ; Get its length
  163.        N0 = N0-1        ; Point to last char in string
  164.        IF not STRCMP S1(n0:n0) "\"
  165.           N0 = N0+1
  166.           CONCAT S1(n0) "\"
  167.           ENDIF
  168.        ENDIF
  169.     S19 = S1&"COM-AND.RMP"  ; Concatenate path and name
  170.     RETURN
  171. ;
  172. ; ----- Subroutine: error
  173. ;    .. Open a window, display, and and await keypress
  174. ;    S0,S1 pass the message(s) to display
  175. ;
  176. Error:
  177.     WOPEN 10,1, 13,77 (contrast) ErrEsc
  178.     ATSAY 11, 3 (contrast) S0(0:73)
  179.     ATSAY 12, 3 (contrast) S1(0:73)
  180.     ATSAY 13,26 (contrast) " Press any key to continue "
  181.     SOUND 880,100
  182.  
  183.     KEYGET S0        ; Wait for any key
  184.     WCLOSE            ; Restore screen under
  185.     RETURN            ; And return to caller
  186. ;
  187. ;    Escape during "Error" window
  188. ;
  189. ErrEsc:
  190.     S0 = ""                 ; Make S0 null
  191.     RETURN            ; And return to KEYGET above
  192. ;
  193. ; ----- Subroutine: Test S0 for a valid (known) keycode
  194. ;    Parameter S0 ------> The keycode being passed
  195. ;    Return:   FLAG(0) <- TRUE if erroneous keycode
  196. ;          S0 <------ The converted keycode (if FLAG(0) false)
  197. ;          N0 <------ The length of the converted keycode
  198. ;
  199. Keycode:
  200.     LJ S0            ; Force left justification
  201.     S0 = S0&""              ; Trim trailing blanks
  202.     SET FLAG(0) OFF     ; Default return value
  203.     LENGTH S0 N0        ; Compute len of parm
  204. ;
  205. ;    Catch decimal and hex numbers here
  206. ;
  207.     IF NUMERIC S0(0:0)    ; Case insensitive test here
  208.        ATOI S0 N0        ; Convert value
  209.        IF (NOT ERROR) and (GE N0 0 and LE N0 255)
  210.           ITOC N0 S0    ; Return value 0-255 as char
  211.           N0 = 1        ; Set rtn length
  212.           RETURN
  213.           ENDIF
  214.        ENDIF
  215. ;
  216. ;    Switch according to length here
  217. ;
  218.     SWITCH N0
  219.        CASE 1        ; 1 char wide
  220.          GOTO TEKE100
  221.        ENDCASE
  222.        CASE 2        ; 2 chars wide
  223.          GOTO TEKE200
  224.        ENDCASE
  225.        CASE 3        ; 3 chars wide
  226.          GOTO TEKE300
  227.        ENDCASE
  228.        CASE 4        ; 4 chars wide
  229.          GOTO TEKE400
  230.        ENDCASE
  231.        CASE 5        ; 5 chars wide
  232.          GOTO TEKE500
  233.        ENDCASE
  234.        CASE 6        ; 6 chars wide
  235.          GOTO TEKE600
  236.        ENDCASE
  237.        DEFAULT
  238.           SET FLAG(0) ON    ; Others are errors
  239.           RETURN
  240.        ENDCASE
  241.     ENDSWITCH
  242. ;
  243. ; ***** Single character keycode here (take char as-is)
  244. ;
  245. TEKE100:
  246.     N0 = 1            ; Return length here (char already in S0)
  247.     RETURN
  248. ;
  249. ; ***** Two character keycode here: First: ^chars
  250. ;
  251. TEKE200:
  252.     IF STRCMP S0(0:0) "^"   ; Caret initially
  253.        UPPER S0        ; Make upper case
  254.        CTOI S0(1:1) N0
  255.        ITOC (N0-64) S0    ; Convert to control form, and place
  256.        N0 = 1
  257.        RETURN
  258.        ENDIF
  259. ;
  260. ;    Catch F0-F9
  261. ;
  262.     IF FIND "F1,F2,F3,F4,F5,F6,F7,F8,F9" S0 N0
  263.        IF NE 0 (N0\3)    ; Modulo divide (remainder)
  264.           SET FLAG(0) ON    ; .. catch e.g. "0,"
  265.           RETURN
  266.           ENDIF
  267.        ITOC 0 S0
  268.        ITOC (0x3b+N0/3) S0(1)
  269.        N0 = 2
  270.        RETURN
  271.        ENDIF
  272. ;
  273. ;    Catch cr and bs here
  274. ;
  275.     SWITCH S0
  276.        CASE "CR"            ; Carriage Rtn
  277.           ITOC 13 S0
  278.           N0 = 1
  279.           RETURN
  280.        ENDCASE
  281.        CASE "BS"            ; Carriage Rtn
  282.           ITOC 8 S0
  283.           N0 = 1
  284.           RETURN
  285.        ENDCASE
  286.     ENDSWITCH
  287. ;
  288. ;    Other pairs are errors
  289. ;
  290.     SET FLAG(0) ON        ; Others are errors
  291.     RETURN
  292. ;
  293. ; ***** Three character keycode here: First, rtn a quoted character
  294. ;
  295. TEKE300:
  296.     IF STRCMP S0(0:0) "`"" and STRCMP S0(2:2) "`""
  297.        S0 = S0(1:1)
  298.        N0 = 1        ; Return length here (char in S0)
  299.        RETURN
  300.        ENDIF
  301. ;
  302. ;    Catch SF0-SF9, CF0-CF9, AF0-AF9, ^F0-^F9
  303. ;
  304.     UPPER S0
  305.     IF FIND "F1,F2,F3,F4,F5,F6,F7,F8,F9" S0(1:2) N0
  306.        IF NE (N0\3) 0    ; Modulo divide (remainder)
  307.           SET FLAG(0) ON    ; .. catch e.g. "0,"
  308.           RETURN
  309.           ENDIF
  310.     ;
  311.     ;    Look at the leading character
  312.     ;
  313.        FIND "SCA^" S0(0:0) N1
  314.        SWITCH N1
  315.           CASE 0        ; AF0,AF1...
  316.         ITOC (0x54+N0/3) S0(1)
  317.           ENDCASE
  318.           CASE 1        ; CF0,CF1...
  319.